home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / bfd / doc / bfd.info-1 < prev    next >
Encoding:
Text File  |  1991-09-29  |  42.0 KB  |  1,339 lines

  1. Info file bfd.info, produced by Makeinfo, -*- Text -*- from input
  2. file bfd.texinfo.
  3.  
  4.    This file documents the BFD library.
  5.  
  6.    Copyright (C) 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of
  9. this manual provided the copyright notice and this permission notice
  10. are preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, subject to the
  14. terms of the GNU General Public License, which includes the provision
  15. that the entire resulting derived work is distributed under the terms
  16. of a permission notice identical to this one.
  17.  
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21.  
  22.  
  23. 
  24. File: bfd.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
  25.  
  26.    This file documents the binary file descriptor library libbfd.
  27.  
  28. * Menu:
  29.  
  30. * Overview::            Overview of BFD
  31. * BFD front end::        BFD front end
  32. * BFD back end::        BFD back end
  33. * Index::            Index
  34.  
  35.  
  36. 
  37. File: bfd.info,  Node: Overview,  Next: BFD front end,  Prev: Top,  Up: Top
  38.  
  39. Introduction
  40. ************
  41.  
  42.    Simply put, BFD is a package which allows applications to use the
  43. same routines to operate on object files whatever the object file
  44. format.  A different object file format can be supported simply by
  45. creating a new BFD back end and adding it to the library.
  46.  
  47.    BFD is split into two parts; the front end and the many back ends.
  48.  
  49.    * memory, and various canonical data structures. The front end
  50.      also decides which back end to use, and when to call back end
  51.      routines.
  52.  
  53.    * end provides a set of calls which the BFD front end can use to
  54.      maintain its canonical form. The back ends also may keep around
  55.      information for their own use, for greater efficiency.
  56.  
  57. * Menu:
  58.  
  59. * History::            History
  60. * How It Works::        How It Works
  61. * What BFD Version 1 Can Do::    What BFD Version 1 Can Do
  62.  
  63.  
  64. 
  65. File: bfd.info,  Node: History,  Next: How It Works,  Prev: Overview,  Up: Overview
  66.  
  67. History
  68. =======
  69.  
  70.    One spur behind BFD was the desire, on the part of the GNU 960
  71. team at Intel Oregon, for interoperability of applications on their
  72. COFF and b.out file formats.  Cygnus was providing GNU support for
  73. the team, and Cygnus was contracted to provide the required
  74. functionality.
  75.  
  76.    The name came from a conversation David Wallace was having with
  77. Richard Stallman about the library: RMS said that it would be quite
  78. hard--David said "BFD".  Stallman was right, but the name stuck.
  79.  
  80.    At the same time, Ready Systems wanted much the same thing, but
  81. for different object file formats: IEEE-695, Oasys, Srecords, a.out
  82. and 68k coff.
  83.  
  84.    BFD was first implemented by Steve Chamberlain (steve@cygnus.com),
  85. John Gilmore (gnu@cygnus.com),  K. Richard Pixley (rich@cygnus.com)
  86. and David Wallace (gumby@cygnus.com) at Cygnus Support in Palo Alto,
  87. California.
  88.  
  89.  
  90. 
  91. File: bfd.info,  Node: How It Works,  Next: What BFD Version 1 Can Do,  Prev: History,  Up: Overview
  92.  
  93. How It Works
  94. ============
  95.  
  96.    To use the library, include `bfd.h' and link with `libbfd.a'.    
  97.  
  98.    BFD provides a common interface to the parts of an object file for
  99. a calling application.
  100.  
  101.    When an application sucessfully opens a target file (object,
  102. archive or whatever) a pointer to an internal structure is returned.
  103. This pointer points to a structure called `bfd', described in
  104. `include/bfd.h'.  Our convention is to call this pointer a BFD, and
  105. instances of it within code `abfd'.  All operations on the target
  106. object file are applied as methods to the BFD.  The mapping is
  107. defined within `bfd.h' in a set of macros, all beginning `bfd'_.
  108.  
  109.    For example, this sequence would do what you would probably
  110. expect: return the number of sections in an object file attached to a
  111. BFD `abfd'.
  112.  
  113.      #include "bfd.h"
  114.      
  115.      unsigned int number_of_sections(abfd)
  116.      bfd *abfd;
  117.      {
  118.        return bfd_count_sections(abfd);
  119.      }
  120.  
  121.    The abstraction used within BFD is that an object file has a
  122. header, a number of sections containing raw data, a set of
  123. relocations, and some symbol information. Also, BFDs opened for
  124. archives have the additional attribute of an index and contain
  125. subordinate BFDs. This approach is fine for a.out and coff, but loses
  126. efficiency when applied to formats such as S-records and IEEE-695.
  127.  
  128.  
  129. 
  130. File: bfd.info,  Node: What BFD Version 1 Can Do,  Prev: How It Works,  Up: Overview
  131.  
  132. What BFD Version 1 Can Do
  133. =========================
  134.  
  135.    As different information from the the object files is required,
  136. BFD reads from different sections of the file and processes them. 
  137. For example a very common operation for the linker is processing
  138. symbol tables.  Each BFD back end provides a routine for converting
  139. between the object file's representation of symbols and an internal
  140. canonical format. When the linker asks for the symbol table of an
  141. object file, it calls through the memory pointer to the relevant BFD
  142. back end routine which reads and converts the table into a canonical
  143. form.  The linker then operates upon the canonical form. When the
  144. link is finished and the linker writes the output file's symbol
  145. table, another BFD back end routine is called which takes the newly
  146. created symbol table and converts it into the chosen output format.
  147.  
  148. * Menu:
  149.  
  150. * BFD information loss::    Information Loss
  151. * Mechanism::            Mechanism
  152.  
  153.  
  154. 
  155. File: bfd.info,  Node: BFD information loss,  Next: Mechanism,  Prev: What BFD Version 1 Can Do,  Up: What BFD Version 1 Can Do
  156.  
  157. Information Loss
  158. ----------------
  159.  
  160.    *Some information is lost due to the nature of the file format.*
  161. The output targets supported by BFD do not provide identical
  162. facilities, and information which may be described in one form has
  163. nowhere to go in another format. One example of this is alignment
  164. information in `b.out'. There is nowhere in an `a.out' format file to
  165. store alignment information on the contained data, so when a file is
  166. linked from `b.out' and an `a.out' image is produced, alignment
  167. information will not propagate to the output file. (The linker will
  168. still use the alignment information internally, so the link is
  169. performed correctly).
  170.  
  171.    Another example is COFF section names. COFF files may contain an
  172. unlimited number of sections, each one with a textual section name.
  173. If the target of the link is a format which does not have many
  174. sections (eg `a.out') or has sections without names (eg the Oasys
  175. format) the link cannot be done simply. You can circumvent this
  176. problem by describing the desired input-to-output section mapping
  177. with the linker command language.
  178.  
  179.    *Information can be lost during canonicalization.* The BFD
  180. internal canonical form of the external formats is not exhaustive;
  181. there are structures in input formats for which there is no direct
  182. representation internally.  This means that the BFD back ends cannot
  183. maintain all possible data richness through the transformation
  184. between external to internal and back to external formats.
  185.  
  186.    This limitation is only a problem when an application reads one
  187. format and writes another.  Each BFD back end is responsible for
  188. maintaining as much data as possible, and the internal BFD canonical
  189. form has structures which are opaque to the BFD core, and exported
  190. only to the back ends. When a file is read in one format, the
  191. canonical form is generated for BFD and the application. At the same
  192. time, the back end saves away any information which may otherwise be
  193. lost. If the data is then written back in the same format, the back
  194. end routine will be able to use the canonical form provided by the
  195. BFD core as well as the information it prepared earlier.  Since there
  196. is a great deal of commonality between back ends, this mechanism is
  197. very useful. There is no information lost for this reason when
  198. linking or copying big endian COFF to little endian COFF, or `a.out'
  199. to `b.out'.  When a mixture of formats is linked, the information is
  200. only lost from the files whose format differs from the destination.
  201.  
  202.  
  203. 
  204. File: bfd.info,  Node: Mechanism,  Prev: BFD information loss,  Up: What BFD Version 1 Can Do
  205.  
  206. Mechanism
  207. ---------
  208.  
  209.    The greatest potential for loss of information is when there is
  210. least overlap between the information provided by the source format,
  211. that stored by the canonical format, and the information needed by
  212. the destination format. A brief description of the canonical form may
  213. help you appreciate what kinds of data you can count on preserving
  214. across conversions.
  215.  
  216. *files*
  217.      Information on target machine architecture, particular
  218.      implementation and format type are stored on a per-file basis.
  219.      Other information includes a demand pageable bit and a write
  220.      protected bit.  Note that information like Unix magic numbers is
  221.      not stored here--only the magic numbers' meaning, so a `ZMAGIC'
  222.      file would have both the demand pageable bit and the write
  223.      protected text bit set.  The byte order of the target is stored
  224.      on a per-file basis, so that big- and little-endian object files
  225.      may be linked with one another.
  226.  
  227. *sections*
  228.      Each section in the input file contains the name of the section,
  229.      the original address in the object file, various flags, size and
  230.      alignment information and pointers into other BFD data structures.
  231.  
  232. *symbols*
  233.      Each symbol contains a pointer to the object file which
  234.      originally defined it, its name, its value, and various flag
  235.      bits.  When a BFD back end reads in a symbol table, the back end
  236.      relocates all symbols to make them relative to the base of the
  237.      section where they were defined.  This ensures that each symbol
  238.      points to its containing section.  Each symbol also has a
  239.      varying amount of hidden data to contain private data for the
  240.      BFD back end.  Since the symbol points to the original file, the
  241.      private data format for that symbol is accessible.  `gld' can
  242.      operate on a collection of symbols of wildly different formats
  243.      without problems.
  244.  
  245.      Normal global and simple local symbols are maintained on output,
  246.      so an output file (no matter its format) will retain symbols
  247.      pointing to functions and to global, static, and common
  248.      variables.  Some symbol information is not worth retaining; in
  249.      `a.out' type information is stored in the symbol table as long
  250.      symbol names.  This information would be useless to most COFF
  251.      debuggers; the linker has command line switches to allow users
  252.      to throw it away.
  253.  
  254.      There is one word of type information within the symbol, so if
  255.      the format supports symbol type information within symbols (for
  256.      example COFF, IEEE, Oasys) and the type is simple enough to fit
  257.      within one word (nearly everything but aggregates) the
  258.      information will be preserved.
  259.  
  260. *relocation level*
  261.      Each canonical BFD relocation record contains a pointer to the
  262.      symbol to relocate to, the offset of the data to relocate, the
  263.      section the data is in and a pointer to a relocation type
  264.      descriptor. Relocation is performed effectively by message
  265.      passing through the relocation type descriptor and symbol
  266.      pointer. It allows relocations to be performed on output data
  267.      using a relocation method only available in one of the input
  268.      formats. For instance, Oasys provides a byte relocation format. 
  269.      A relocation record requesting this relocation type would point
  270.      indirectly to a routine to perform this, so the relocation may
  271.      be performed on a byte being written to a COFF file, even though
  272.      68k COFF has no such relocation type.
  273.  
  274. *line numbers*
  275.      Object formats can contain, for debugging purposes, some form of
  276.      mapping between symbols, source line numbers, and addresses in
  277.      the output file.  These addresses have to be relocated along
  278.      with the symbol information.  Each symbol with an associated
  279.      list of line number records points to the first record of the
  280.      list.  The head of a line number list consists of a pointer to
  281.      the symbol, which allows divination of the address of the
  282.      function whose line number is being described. The rest of the
  283.      list is made up of pairs: offsets into the section and line
  284.      numbers. Any format which can simply derive this information can
  285.      pass it successfully between formats (COFF, IEEE and Oasys).
  286.  
  287.  
  288. 
  289. File: bfd.info,  Node: BFD front end,  Next: BFD back end,  Prev: Overview,  Up: Top
  290.  
  291. BFD front end
  292. *************
  293.  
  294. `typedef bfd'
  295. =============
  296.  
  297.    A BFD is has type `bfd'; objects of this type are the cornerstone
  298. of any application using `libbfd'. References though the BFD and to
  299. data in the BFD give the entire BFD functionality.
  300.  
  301.    Here is the struct used to define the type `bfd'.  This contains
  302. the major data about the file, and contains pointers to the rest of
  303. the data.
  304.  
  305.      struct _bfd 
  306.      {
  307.  
  308.    The filename the application opened the BFD with.
  309.  
  310.        CONST char *filename;
  311.  
  312.    A pointer to the target jump table.
  313.  
  314.        struct bfd_target *xvec;
  315.  
  316.    To avoid dragging too many header files into every file that
  317. includes `bfd.h', IOSTREAM has been declared as a "char *", and MTIME
  318. as a "long".  Their correct types, to which they are cast when used,
  319. are "FILE *" and "time_t".
  320.  
  321.    The iostream is the result of an fopen on the filename.
  322.  
  323.        char *iostream;
  324.  
  325.    Is the file being cached *Note File Caching::.
  326.  
  327.        boolean cacheable;
  328.  
  329.    Marks whether there was a default target specified when the BFD
  330. was opened. This is used to select what matching algorithm to use to
  331. chose the back end.
  332.  
  333.        boolean target_defaulted;
  334.  
  335.    The caching routines use these to maintain a least-recently-used
  336. list of BFDs (*note File Caching::.).
  337.  
  338.        struct _bfd *lru_prev, *lru_next;
  339.  
  340.    When a file is closed by the caching routines, BFD retains state
  341. information on the file here:
  342.  
  343.        file_ptr where;
  344.  
  345.    and here:
  346.  
  347.        boolean opened_once;
  348.  
  349.        boolean mtime_set;
  350.  
  351.    File modified time
  352.  
  353.        long mtime;
  354.  
  355.    Reserved for an unimplemented file locking extension.
  356.  
  357.      int ifd;
  358.  
  359.    The format which belongs to the BFD.
  360.  
  361.        bfd_format format;
  362.  
  363.    The direction the BFD was opened with
  364.  
  365.        enum bfd_direction {no_direction = 0,
  366.                             read_direction = 1,
  367.                             write_direction = 2,
  368.                             both_direction = 3} direction;
  369.  
  370.    Format_specific flags
  371.  
  372.        flagword flags;
  373.  
  374.    Currently my_archive is tested before adding origin to anything. I
  375. believe that this can become always an add of origin, with origin set
  376. to 0 for non archive files.
  377.  
  378.        file_ptr origin;
  379.  
  380.    Remember when output has begun, to stop strange things happening.
  381.  
  382.        boolean output_has_begun;
  383.  
  384.    Pointer to linked list of sections
  385.  
  386.        struct sec  *sections;
  387.  
  388.    The number of sections
  389.  
  390.        unsigned int section_count;
  391.  
  392.    Stuff only useful for object files: The start address.
  393.  
  394.        bfd_vma start_address;
  395.  
  396.    Used for input and output
  397.  
  398.        unsigned int symcount;
  399.  
  400.    Symbol table for output BFD
  401.  
  402.        struct symbol_cache_entry  **outsymbols;
  403.  
  404.    Architecture of object machine, eg m68k
  405.  
  406.        enum bfd_architecture obj_arch;
  407.  
  408.    Particular machine within arch, e.g. 68010
  409.  
  410.        unsigned long obj_machine;
  411.  
  412.    Stuff only useful for archives:
  413.  
  414.        PTR arelt_data;              
  415.        struct _bfd *my_archive;     
  416.        struct _bfd *next;           
  417.        struct _bfd *archive_head;   
  418.        boolean has_armap;
  419.  
  420.    Used by the back end to hold private data.
  421.  
  422.        PTR tdata;
  423.  
  424.    Used by the application to hold private data
  425.  
  426.        PTR usrdata;
  427.  
  428.    Where all the allocated stuff under this BFD goes (*note Memory
  429. Usage::.).
  430.  
  431.        struct obstack memory;
  432.      };
  433.  
  434. `bfd_set_start_address'
  435. .......................
  436.  
  437.     Marks the entry point of an output BFD. Returns `true' on success,
  438. `false' otherwise.
  439.  
  440.      boolean bfd_set_start_address(bfd *, bfd_vma);
  441.  
  442. `bfd_get_mtime'
  443. ...............
  444.  
  445.     Return cached file modification time (e.g. as read from archive
  446. header for archive members, or from file system if we have been
  447. called before); else determine modify time, cache it, and return it.
  448.  
  449.      long bfd_get_mtime(bfd *);
  450.  
  451. `stuff'
  452. .......
  453.  
  454.  
  455.           #define bfd_sizeof_headers(abfd, reloc) \
  456.           BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
  457.      
  458.      #define bfd_find_nearest_line(abfd, section, symbols, offset, filename_ptr, func, line_ptr) \
  459.           BFD_SEND (abfd, _bfd_find_nearest_line,  (abfd, section, symbols, offset, filename_ptr, func, line_ptr))
  460.      
  461.      #define bfd_debug_info_start(abfd) \
  462.              BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
  463.      
  464.      #define bfd_debug_info_end(abfd) \
  465.              BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
  466.      
  467.      #define bfd_debug_info_accumulate(abfd, section) \
  468.              BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
  469.      
  470.      #define bfd_stat_arch_elt(abfd, stat) \
  471.              BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
  472.      
  473.      #define bfd_coff_swap_aux_in(a,e,t,c,i) \
  474.              BFD_SEND (a, _bfd_coff_swap_aux_in, (a,e,t,c,i))
  475.      
  476.      #define bfd_coff_swap_sym_in(a,e,i) \
  477.              BFD_SEND (a, _bfd_coff_swap_sym_in, (a,e,i))
  478.      
  479.      #define bfd_coff_swap_lineno_in(a,e,i) \
  480.              BFD_SEND ( a, _bfd_coff_swap_lineno_in, (a,e,i))
  481.  
  482. * Menu:
  483.  
  484. * Memory Usage::        Memory Usage
  485.  
  486.  
  487. 
  488. File: bfd.info,  Node: Memory Usage,  Prev: BFD front end,  Up: BFD front end
  489.  
  490. Memory Usage
  491. ============
  492.  
  493.    BFD keeps all its internal structures in obstacks. There is one
  494. obstack per open BFD file, into which the current state is stored.
  495. When a BFD is closed, the obstack is deleted, and so everything which
  496. has been allocated by libbfd for the closing file will be thrown away.
  497.  
  498.    BFD will not free anything created by an application, but pointers
  499. into `bfd' structures will be invalidated on a `bfd_close'; for
  500. example, after a `bfd_close' the vector passed to
  501. `bfd_canonicalize_symtab' will still be around, since it has been
  502. allocated by the application, but the data that it pointed to will be
  503. lost.
  504.  
  505.    The general rule is not to close a BFD until all operations
  506. dependent upon data from the BFD have been completed, or all the data
  507. from within the file has been copied. To help with the management of
  508. memory, there is a function (`bfd_alloc_size') which returns the
  509. number of bytes in obstacks associated with the supplied BFD. This
  510. could be used to select the greediest open BFD, close it to reclaim
  511. the memory, perform some operation and reopen the BFD again, to get a
  512. fresh copy of the data structures.
  513.  
  514.  
  515. 
  516. File: bfd.info,  Node: Sections,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  517.  
  518. Sections
  519. ========
  520.  
  521.    Sections are supported in BFD in `section.c'.
  522.  
  523.    The raw data contained within a BFD is maintained through the
  524. section abstraction.  A single BFD may have any number of sections,
  525. and keeps hold of them by pointing to the first, each one points to
  526. the next in the list.
  527.  
  528. * Menu:
  529.  
  530. * Section Input::
  531. * Section Output::
  532. * typedef asection::
  533. * section prototypes::
  534.  
  535.  
  536. 
  537. File: bfd.info,  Node: Section Input,  Next: Section Output,  Up: Sections
  538.  
  539. Section Input
  540. -------------
  541.  
  542.    When a BFD is opened for reading, the section structures are
  543. created and attached to the BFD.
  544.  
  545.    Each section has a name which describes the section in the outside
  546. world - for example, `a.out' would contain at least three sections,
  547. called `.text', `.data' and `.bss'.
  548.  
  549.    Sometimes a BFD will contain more than the 'natural' number of
  550. sections. A back end may attach other sections containing constructor
  551. data, or an application may add a section (using bfd_make_section) to
  552. the sections attached to an already open BFD. For example, the linker
  553. creates a supernumary section `COMMON' for each input file's BFD to
  554. hold information about common storage.
  555.  
  556.    The raw data is not necessarily read in at the same time as the
  557. section descriptor is created. Some targets may leave the data in
  558. place until a `bfd_get_section_contents' call is made. Other back
  559. ends may read in all the data at once - For example; an S-record file
  560. has to be read once to determine the size of the data. An IEEE-695
  561. file doesn't contain raw data in sections, but data and relocation
  562. expressions intermixed, so the data area has to be parsed to get out
  563. the data and relocations.
  564.  
  565.  
  566. 
  567. File: bfd.info,  Node: Section Output,  Next: typedef asection,  Prev: Section Input,  Up: Sections
  568.  
  569. Section Output
  570. --------------
  571.  
  572.    To write a new object style BFD, the various sections to be
  573. written have to be created. They are attached to the BFD in the same
  574. way as input sections, data is written to the sections using
  575. `bfd_set_section_contents'.
  576.  
  577.    The linker uses the fields `output_section' and `output_offset' to
  578. create an output file.
  579.  
  580.    The data to be written comes from input sections attached to the
  581. output sections.  The output section structure can be considered a
  582. filter for the input section, the output section determines the vma
  583. of the output data and the name, but the input section determines the
  584. offset into the output section of the data to be written.
  585.  
  586.    Eg to create a section "O", starting at 0x100, 0x123 long,
  587. containing two subsections, "A" at offset 0x0 (ie at vma 0x100) and
  588. "B" at offset 0x20 (ie at vma 0x120) the structures would look like:
  589.  
  590.  
  591.              section name          "A"
  592.           output_offset   0x00
  593.           size            0x20
  594.           output_section ----------->  section name    "O"
  595.                                   |    vma             0x100
  596.         section name          "B" |    size            0x123
  597.           output_offset   0x20    |
  598.           size            0x103   |
  599.           output_section  --------|
  600.  
  601.  
  602. 
  603. File: bfd.info,  Node: typedef asection,  Next: section prototypes,  Prev: Section Output,  Up: Sections
  604.  
  605. typedef asection
  606. ----------------
  607.  
  608.    The shape of a section struct:
  609.  
  610.      typedef struct sec {
  611.  
  612.    The name of the section, the name isn't a copy, the pointer is the
  613. same as that passed to bfd_make_section.
  614.  
  615.          CONST char *name;
  616.  
  617.    The next section in the list belonging to the BFD, or NULL.
  618.  
  619.          struct sec *next;
  620.  
  621.    The field flags contains attributes of the section. Some of these
  622. flags are read in from the object file, and some are synthesized from
  623. other information.
  624.  
  625.      flagword flags;
  626.  
  627.      #define SEC_NO_FLAGS   0x000
  628.  
  629.    Tells the OS to allocate space for this section when loaded.  This
  630. would clear for a section containing debug information only.
  631.  
  632.      #define SEC_ALLOC      0x001
  633.  
  634.    Tells the OS to load the section from the file when loading.  This
  635. would be clear for a .bss section
  636.  
  637.      #define SEC_LOAD       0x002
  638.  
  639.    The section contains data still to be relocated, so there will be
  640. some relocation information too.
  641.  
  642.      #define SEC_RELOC      0x004
  643.  
  644.    Obsolete
  645.  
  646.      #define SEC_BALIGN     0x008
  647.  
  648.    A signal to the OS that the section contains read only data.
  649.  
  650.      #define SEC_READONLY   0x010
  651.  
  652.    The section contains code only.
  653.  
  654.      #define SEC_CODE       0x020
  655.  
  656.    The section contains data only.
  657.  
  658.      #define SEC_DATA        0x040
  659.  
  660.    The section will reside in ROM.
  661.  
  662.      #define SEC_ROM        0x080
  663.  
  664.    The section contains constructor information. This section type is
  665. used by the linker to create lists of constructors and destructors
  666. used by `g++'. When a back end sees a symbol which should be used in
  667. a constructor list, it creates a new section for the type of name (eg
  668. `__CTOR_LIST__'), attaches the symbol to it and builds a relocation.
  669. To build the lists of constructors, all the linker has to to is
  670. catenate all the sections called `__CTOR_LIST__' and relocte the data
  671. contained within - exactly the operations it would peform on standard
  672. data.
  673.  
  674.      #define SEC_CONSTRUCTOR 0x100
  675.  
  676.    The section is a constuctor, and should be placed at the end of
  677. the ..
  678.  
  679.      #define SEC_CONSTRUCTOR_TEXT 0x1100
  680.  
  681.      #define SEC_CONSTRUCTOR_DATA 0x2100
  682.  
  683.      #define SEC_CONSTRUCTOR_BSS  0x3100
  684.  
  685.    The section has contents - a bss section could be `SEC_ALLOC' |
  686. `SEC_HAS_CONTENTS', a debug section could be `SEC_HAS_CONTENTS'
  687.  
  688.      #define SEC_HAS_CONTENTS 0x200
  689.  
  690.    An instruction to the linker not to output sections containing
  691. this flag even if they have information which would normally be
  692. written.
  693.  
  694.      #define SEC_NEVER_LOAD 0x400
  695.  
  696.    The base address of the section in the address space of the target.
  697.  
  698.         bfd_vma vma;
  699.  
  700.    The size of the section in bytes of the loaded section. This
  701. contains a value even if the section has no contents (eg, the size of
  702. `.bss').
  703.  
  704.         bfd_size_type size;
  705.  
  706.    If this section is going to be output, then this value is the
  707. offset into the output section of the first byte in the input
  708. section. Eg, if this was going to start at the 100th byte in the
  709. output section, this value would be 100.
  710.  
  711.         bfd_vma output_offset;
  712.  
  713.    The output section through which to map on output.
  714.  
  715.         struct sec *output_section;
  716.  
  717.    The alignment requirement of the section, as an exponent - eg 3
  718. aligns to 2^3 (or 8)
  719.  
  720.         unsigned int alignment_power;
  721.  
  722.    If an input section, a pointer to a vector of relocation records
  723. for the data in this section.
  724.  
  725.         struct reloc_cache_entry *relocation;
  726.  
  727.    If an output section, a pointer to a vector of pointers to
  728. relocation records for the data in this section.
  729.  
  730.         struct reloc_cache_entry **orelocation;
  731.  
  732.    The number of relocation records in one of the above
  733.  
  734.         unsigned reloc_count;
  735.  
  736.    Which section is it 0..nth
  737.  
  738.         int index;
  739.  
  740.    Information below is back end specific - and not always used or
  741. updated
  742.  
  743.    File position of section data
  744.  
  745.         file_ptr filepos;
  746.  
  747.    File position of relocation info
  748.  
  749.         file_ptr rel_filepos;
  750.  
  751.    File position of line data
  752.  
  753.         file_ptr line_filepos;
  754.  
  755.    Pointer to data for applications
  756.  
  757.         PTR userdata;
  758.  
  759.         struct lang_output_section *otheruserdata;
  760.  
  761.    Attached line number information
  762.  
  763.         alent *lineno;
  764.  
  765.    Number of line number records
  766.  
  767.         unsigned int lineno_count;
  768.  
  769.    When a section is being output, this value changes as more
  770. linenumbers are written out
  771.  
  772.         file_ptr moving_line_filepos;
  773.  
  774.    what the section number is in the target world
  775.  
  776.         unsigned int target_index;
  777.  
  778.         PTR used_by_bfd;
  779.  
  780.    If this is a constructor section then here is a list of the
  781. relocations created to relocate items within it.
  782.  
  783.         struct relent_chain *constructor_chain;
  784.  
  785.    The BFD which owns the section.
  786.  
  787.         bfd *owner;
  788.  
  789.      } asection ;
  790.  
  791.  
  792. 
  793. File: bfd.info,  Node: section prototypes,  Next: Section,  Prev: typedef section,  Up: Sections
  794.  
  795. section prototypes
  796. ------------------
  797.  
  798. `bfd_get_section_by_name'
  799. .........................
  800.  
  801.    Runs through the provided ABFD and returns the `asection' who's
  802. name matches that provided, otherwise NULL. *Note Sections::, for
  803. more information.
  804.  
  805.      asection * bfd_get_section_by_name(bfd *abfd, CONST char *name);
  806.  
  807. `bfd_make_section'
  808. ..................
  809.  
  810.    This function creates a new empty section called NAME and attaches
  811. it to the end of the chain of sections for the BFD supplied. An
  812. attempt to create a section with a name which is already in use,
  813. returns the old section by that name instead.
  814.  
  815.    Possible errors are:
  816.  
  817. `invalid_operation'
  818.      If output has already started for this BFD.
  819.  
  820. `no_memory'
  821.      If obstack alloc fails.
  822.  
  823.      asection * bfd_make_section(bfd *, CONST char *name);
  824.  
  825. `bfd_set_section_flags'
  826. .......................
  827.  
  828.    Attempts to set the attributes of the section named in the BFD
  829. supplied to the value. Returns true on success, false on error. 
  830. Possible error returns are:
  831.  
  832. `invalid operation'
  833.      The section cannot have one or more of the attributes requested.
  834.      For example, a .bss section in `a.out' may not have the
  835.      `SEC_HAS_CONTENTS' field set.
  836.  
  837.      boolean bfd_set_section_flags(bfd *, asection *, flagword);
  838.  
  839. `bfd_map_over_sections'
  840. .......................
  841.  
  842.    Calls the provided function FUNC for each section attached to the
  843. BFD ABFD, passing OBJ as an argument. The function will be called as
  844. if by
  845.  
  846.        func(abfd, the_section, obj);
  847.  
  848.      void bfd_map_over_sections(bfd *abfd, void (*func)(), PTR obj);
  849.  
  850.    This is the prefered method for iterating over sections, an
  851. alternative would be to use a loop:
  852.  
  853.         section *p;
  854.         for (p = abfd->sections; p != NULL; p = p->next)
  855.            func(abfd, p, ...)
  856.  
  857. `bfd_set_section_size'
  858. ......................
  859.  
  860.    Sets SECTION to the size VAL. If the operation is ok, then `true'
  861. is returned, else `false'.
  862.  
  863.    Possible error returns:
  864.  
  865. `invalid_operation'
  866.      Writing has started to the BFD, so setting the size is invalid
  867.  
  868.      boolean bfd_set_section_size(bfd *, asection *, bfd_size_type val);
  869.  
  870. `bfd_set_section_contents'
  871. ..........................
  872.  
  873.    Sets the contents of the section SECTION in BFD ABFD to the data
  874. starting in memory at DATA. The data is written to the output section
  875. starting at offset OFFSET for COUNT bytes.
  876.  
  877.    Normally `true' is returned, else `false'. Possible error returns
  878. are:
  879.  
  880. `no_contents'
  881.      The output section does not have the `SEC_HAS_CONTENTS'
  882.      attribute, so nothing can be written to it.
  883.  
  884. `and some more too'
  885.    This routine is front end to the back end function
  886. `_bfd_set_section_contents'.
  887.  
  888.      boolean bfd_set_section_contents(bfd *abfd,        
  889.               asection *section,
  890.               PTR data,
  891.               file_ptr offset,
  892.               bfd_size_type count);
  893.  
  894. `bfd_get_section_contents'
  895. ..........................
  896.  
  897.    This function reads data from SECTION in BFD ABFD into memory
  898. starting at LOCATION. The data is read at an offset of OFFSET from
  899. the start of the input section, and is read for COUNT bytes.
  900.  
  901.    If the contents of a constuctor with the `SEC_CONSTUCTOR' flag set
  902. are requested, then the LOCATION is filled with zeroes.
  903.  
  904.    If no errors occur, `true' is returned, else `false'.  Possible
  905. errors are:
  906.  
  907. `unknown yet'
  908.      boolean bfd_get_section_contents(bfd *abfd, asection *section, PTR location,
  909.               file_ptr offset, bfd_size_type count);
  910.  
  911.  
  912. 
  913. File: bfd.info,  Node: Symbols,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  914.  
  915. Symbols
  916. =======
  917.  
  918.    BFD trys to maintain as much symbol information as it can when it
  919. moves information from file to file. BFD passes information to
  920. applications though the `asymbol' structure. When the application
  921. requests the symbol table, BFD reads the table in the native form and
  922. translates parts of it into the internal format. To maintain more
  923. than the infomation passed to applications some targets keep some
  924. information 'behind the sceans', in a structure only the particular
  925. back end knows about. For example, the coff back end keeps the
  926. original symbol table structure as well as the canonical structure
  927. when a BFD is read in. On output, the coff back end can reconstruct
  928. the output symbol table so that no information is lost, even
  929. information unique to coff which BFD doesn't know or understand. If a
  930. coff symbol table was read, but was written through an a.out back
  931. end, all the coff specific information would be lost. (.. until BFD 2
  932. :).
  933.  
  934.    The symbol table of a BFD is not necessarily read in until a
  935. canonicalize request is made. Then the BFD back end fills in a table
  936. provided by the application with pointers to the canonical information.
  937.  
  938.    To output symbols, the application provides BFD with a table of
  939. pointers to pointers to `asymbol's. This allows applications like the
  940. linker to output a symbol as read, since the 'behind the sceens'
  941. information will be still available.
  942.  
  943. * Menu:
  944.  
  945. * Reading Symbols::
  946. * Writing Symbols::
  947. * typedef asymbol::
  948. * symbol handling functions::
  949.  
  950.  
  951. 
  952. File: bfd.info,  Node: Reading Symbols,  Next: Writing Symbols,  Prev: Symbols,  Up: Symbols
  953.  
  954. Reading Symbols
  955. ---------------
  956.  
  957.    There are two stages to reading a symbol table from a BFD;
  958. allocating storage, and the actual reading process. This is an
  959. excerpt from an appliction which reads the symbol table:
  960.  
  961.        unsigned int storage_needed;
  962.        asymbol **symbol_table;
  963.        unsigned int number_of_symbols;
  964.        unsigned int i;
  965.      
  966.        storage_needed = get_symtab_upper_bound (abfd);
  967.      
  968.        if (storage_needed == 0) {
  969.           return ;
  970.        }
  971.        symbol_table = (asymbol **) malloc (storage_needed);
  972.          ...
  973.        number_of_symbols = 
  974.           bfd_canonicalize_symtab (abfd, symbol_table); 
  975.      
  976.        for (i = 0; i < number_of_symbols; i++) {
  977.           process_symbol (symbol_table[i]);
  978.        }
  979.  
  980.    All storage for the symbols themselves is in an obstack connected
  981. to the BFD, and is freed when the BFD is closed.
  982.  
  983.  
  984. 
  985. File: bfd.info,  Node: Writing Symbols,  Next: typedef asymbol,  Prev: Reading Symbols,  Up: Symbols
  986.  
  987. Writing Symbols
  988. ---------------
  989.  
  990.    Writing of a symbol table is automatic when a BFD open for writing
  991. is closed. The application attaches a vector of pointers to pointers
  992. to symbols to the BFD being written, and fills in the symbol count.
  993. The close and cleanup code reads through the table provided and
  994. performs all the necessary operations. The outputing code must always
  995. be provided with an 'owned' symbol; one which has come from another
  996. BFD, or one which has been created using `bfd_make_empty_symbol'.
  997.  
  998.    An example showing the creation of a symbol table with only one
  999. element:
  1000.  
  1001.      #include "bfd.h"
  1002.      main() 
  1003.      {
  1004.        bfd *abfd;
  1005.        asymbol *ptrs[2];
  1006.        asymbol *new;
  1007.      
  1008.        abfd = bfd_openw("foo","a.out-sunos-big");
  1009.        bfd_set_format(abfd, bfd_object);
  1010.        new = bfd_make_empty_symbol(abfd);
  1011.        new->name = "dummy_symbol";
  1012.        new->section = (asection *)0;
  1013.        new->flags = BSF_ABSOLUTE | BSF_GLOBAL;
  1014.        new->value = 0x12345;
  1015.      
  1016.        ptrs[0] = new;
  1017.        ptrs[1] = (asymbol *)0;
  1018.      
  1019.        bfd_set_symtab(abfd, ptrs, 1);
  1020.        bfd_close(abfd);
  1021.      }
  1022.      
  1023.      ./makesym 
  1024.      nm foo
  1025.      00012345 A dummy_symbol
  1026.  
  1027.    Many formats cannot represent arbitary symbol information; for
  1028. instance the `a.out' object format does not allow an arbitary number
  1029. of sections. A symbol pointing to a section which is not one of
  1030. `.text', `.data' or `.bss' cannot be described.
  1031.  
  1032.  
  1033. 
  1034. File: bfd.info,  Node: typedef asymbol,  Next: symbol handling functions,  Prev: Writing Symbols,  Up: Symbols
  1035.  
  1036. typedef asymbol
  1037. ---------------
  1038.  
  1039.    An `asymbol' has the form:
  1040.  
  1041.      typedef struct symbol_cache_entry 
  1042.      {
  1043.  
  1044.    A pointer to the BFD which owns the symbol. This information is
  1045. necessary so that a back end can work out what additional (invisible
  1046. to the application writer) information is carried with the symbol.
  1047.  
  1048.        struct _bfd *the_bfd;
  1049.  
  1050.    The text of the symbol. The name is left alone, and not copied -
  1051. the application may not alter it.
  1052.  
  1053.         CONST char *name;
  1054.  
  1055.    The value of the symbol.
  1056.  
  1057.         symvalue value;
  1058.  
  1059.    Attributes of a symbol:
  1060.  
  1061.      #define BSF_NO_FLAGS    0x00
  1062.  
  1063.    The symbol has local scope; `static' in `C'. The value is the
  1064. offset into the section of the data.
  1065.  
  1066.      #define BSF_LOCAL    0x01
  1067.  
  1068.    The symbol has global scope; initialized data in `C'. The value is
  1069. the offset into the section of the data.
  1070.  
  1071.      #define BSF_GLOBAL    0x02
  1072.  
  1073.    Obsolete
  1074.  
  1075.      #define BSF_IMPORT    0x04
  1076.  
  1077.    The symbol has global scope, and is exported. The value is the
  1078. offset into the section of the data.
  1079.  
  1080.      #define BSF_EXPORT    0x08
  1081.  
  1082.    The symbol is undefined. `extern' in `C'. The value has no meaning.
  1083.  
  1084.      #define BSF_UNDEFINED    0x10    
  1085.  
  1086.    The symbol is common, initialized to zero; default in `C'. The
  1087. value is the size of the object in bytes.
  1088.  
  1089.      #define BSF_FORT_COMM    0x20    
  1090.  
  1091.    A normal `C' symbol would be one of: `BSF_LOCAL', `BSF_FORT_COMM',
  1092. `BSF_UNDEFINED' or `BSF_EXPORT|BSD_GLOBAL'
  1093.  
  1094.    The symbol is a debugging record. The value has an arbitary meaning.
  1095.  
  1096.      #define BSF_DEBUGGING    0x40
  1097.  
  1098.    The symbol has no section attached, any value is the actual value
  1099. and is not a relative offset to a section.
  1100.  
  1101.      #define BSF_ABSOLUTE    0x80
  1102.  
  1103.    Used by the linker
  1104.  
  1105.      #define BSF_KEEP        0x10000
  1106.      #define BSF_KEEP_G      0x80000
  1107.  
  1108.    Unused
  1109.  
  1110.      #define BSF_WEAK        0x100000
  1111.      #define BSF_CTOR        0x200000 
  1112.      #define BSF_FAKE        0x400000
  1113.  
  1114.    The symbol used to be a common symbol, but now it is allocated.
  1115.  
  1116.      #define BSF_OLD_COMMON  0x800000
  1117.  
  1118.    The default value for common data.
  1119.  
  1120.      #define BFD_FORT_COMM_DEFAULT_VALUE 0
  1121.  
  1122.    In some files the type of a symbol sometimes alters its location
  1123. in an output file - ie in coff a `ISFCN' symbol which is also `C_EXT'
  1124. symbol appears where it was declared and not at the end of a section.
  1125. This bit is set by the target BFD part to convey this information.
  1126.  
  1127.      #define BSF_NOT_AT_END    0x40000
  1128.  
  1129.    Signal that the symbol is the label of constructor section.
  1130.  
  1131.      #define BSF_CONSTRUCTOR   0x1000000
  1132.  
  1133.    Signal that the symbol is a warning symbol. If the symbol is a
  1134. warning symbol, then the value field (I know this is tacky) will
  1135. point to the asymbol which when referenced will cause the warning.
  1136.  
  1137.      #define BSF_WARNING       0x2000000
  1138.  
  1139.    Signal that the symbol is indirect. The value of the symbol is a
  1140. pointer to an undefined asymbol which contains the name to use instead.
  1141.  
  1142.      #define BSF_INDIRECT     0x4000000
  1143.  
  1144.        flagword flags;
  1145.  
  1146.    A pointer to the section to which this symbol is relative, or 0 if
  1147. the symbol is absolute or undefined. Note that it is not sufficient
  1148. to set this location to 0 to mark a symbol as absolute - the flag
  1149. `BSF_ABSOLUTE' must be set also.
  1150.  
  1151.        struct sec *section;
  1152.  
  1153.    Back end special data. This is being phased out in favour of
  1154. making this a union.
  1155.  
  1156.        PTR udata;    
  1157.      } asymbol;
  1158.  
  1159.  
  1160. 
  1161. File: bfd.info,  Node: symbol handling functions,  Next: Symbols,  Prev: typedef asymbol,  Up: Symbols
  1162.  
  1163. Symbol Handling Functions
  1164. -------------------------
  1165.  
  1166. `get_symtab_upper_bound'
  1167. ........................
  1168.  
  1169.    Returns the number of bytes required in a vector of pointers to
  1170. `asymbols' for all the symbols in the supplied BFD, including a
  1171. terminal NULL pointer. If there are no symbols in the BFD, then 0 is
  1172. returned.
  1173.  
  1174.      #define get_symtab_upper_bound(abfd) \
  1175.           BFD_SEND (abfd, _get_symtab_upper_bound, (abfd))
  1176.  
  1177. `bfd_canonicalize_symtab'
  1178. .........................
  1179.  
  1180.    Supplied a BFD and a pointer to an uninitialized vector of pointers.
  1181. This reads in the symbols from the BFD, and fills in the table with
  1182. pointers to the symbols, and a trailing NULL. The routine returns the
  1183. actual number of symbol pointers not including the NULL.
  1184.  
  1185.      #define bfd_canonicalize_symtab(abfd, location) \
  1186.           BFD_SEND (abfd, _bfd_canonicalize_symtab,\
  1187.                        (abfd, location))
  1188.  
  1189. `bfd_set_symtab'
  1190. ................
  1191.  
  1192.    Provided a table of pointers to to symbols and a count, writes to
  1193. the output BFD the symbols when closed.
  1194.  
  1195.      boolean bfd_set_symtab(bfd *, asymbol **, unsigned int );
  1196.  
  1197. `bfd_print_symbol_vandf'
  1198. ........................
  1199.  
  1200.    Prints the value and flags of the symbol supplied to the stream
  1201. file.
  1202.  
  1203.      void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
  1204.  
  1205. `bfd_make_empty_symbol'
  1206. .......................
  1207.  
  1208.    This function creates a new `asymbol' structure for the BFD, and
  1209. returns a pointer to it.
  1210.  
  1211.    This routine is necessary, since each back end has private
  1212. information surrounding the `asymbol'. Building your own `asymbol'
  1213. and pointing to it will not create the private information, and will
  1214. cause problems later on.
  1215.  
  1216.      #define bfd_make_empty_symbol(abfd) \
  1217.           BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
  1218.  
  1219.  
  1220. 
  1221. File: bfd.info,  Node: Archives,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  1222.  
  1223. Archives
  1224. ========
  1225.  
  1226.    Gumby, you promised to write this bit...
  1227.  
  1228.    Archives are supported in BFD in `archive.c'.
  1229.  
  1230.    An archive is represented internally just like another BFD, with a
  1231. pointer to a chain of contained BFDs. Archives can be created by
  1232. opening BFDs, linking them together and attaching them as children to
  1233. another BFD and then closing the parent BFD.
  1234.  
  1235. `bfd_get_next_mapent'
  1236. .....................
  1237.  
  1238.    What this does
  1239.  
  1240.      symindex bfd_get_next_mapent(bfd *, symindex, carsym **);
  1241.  
  1242. `bfd_set_archive_head'
  1243. ......................
  1244.  
  1245.     Used whilst processing archives. Sets the head of the chain of
  1246. BFDs contained in an archive to NEW_HEAD. (see chapter on archives)
  1247.  
  1248.      boolean bfd_set_archive_head(bfd *output, bfd *new_head);
  1249.  
  1250. `bfd_get_elt_at_index'
  1251. ......................
  1252.  
  1253.    Return the sub bfd contained within the archive at archive index n.
  1254.  
  1255.      bfd * bfd_get_elt_at_index(bfd *, int);
  1256.  
  1257. `bfd_openr_next_archived_file'
  1258. ..............................
  1259.  
  1260.    Initially provided a BFD containing an archive and NULL, opens a
  1261. BFD on the first contained element and returns that. Subsequent calls
  1262. to bfd_openr_next_archived_file should pass the archive and the
  1263. previous return value to return a created BFD to the next contained
  1264. element.  NULL is returned when there are no more.
  1265.  
  1266.      bfd* bfd_openr_next_archived_file(bfd *archive, bfd *previous);
  1267.  
  1268.  
  1269. 
  1270. File: bfd.info,  Node: Formats,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  1271.  
  1272. File Formats
  1273. ============
  1274.  
  1275.    A format is a BFD concept of high level file contents. The formats
  1276. supported by BFD are:
  1277.  
  1278. `bfd_object'
  1279.      The BFD may contain data, symbols, relocations and debug info.
  1280.  
  1281. `bfd_archive'
  1282.      The BFD contains other BFDs and an optional index.
  1283.  
  1284. `bfd_core'
  1285.      The BFD contains the result of an executable core dump.
  1286.  
  1287. `bfd_check_format'
  1288. ..................
  1289.  
  1290.    This routine is supplied a BFD and a format. It attempts to verify
  1291. if the file attached to the BFD is indeed compatible with the format
  1292. specified (ie, one of `bfd_object', `bfd_archive' or `bfd_core').
  1293.  
  1294.    If the BFD has been set to a specific TARGET before the call, only
  1295. the named target and format combination will be checked. If the
  1296. target has not been set, or has been set to `default' then all the
  1297. known target backends will be interrogated to determine a match.
  1298.  
  1299.    The function returns `true' on success, otherwise `false' with one
  1300. of the following error codes:
  1301.  
  1302. `'
  1303.      invalid_operation if `format' is not one of `bfd_object',
  1304.      `bfd_archive' or `bfd_core'.
  1305.  
  1306. `system_call_error'
  1307.      if an error occured during a read -  even some file mismatches
  1308.      can cause system_call_errros
  1309.  
  1310. `file_not_recognised'
  1311.      none of the backends recognised the file format
  1312.  
  1313. `file_ambiguously_recognized'
  1314.      more than one backend recognised the file format.
  1315.  
  1316.      boolean bfd_check_format(bfd *abfd, bfd_format format);
  1317.  
  1318. `bfd_set_format'
  1319. ................
  1320.  
  1321.    This function sets the file format of the supplied BFD to the
  1322. format requested. If the target set in the BFD does not support the
  1323. format requested, the format is illegal or the BFD is not open for
  1324. writing than an error occurs.
  1325.  
  1326.      boolean bfd_set_format(bfd *, bfd_format);
  1327.  
  1328. `bfd_format_string'
  1329. ...................
  1330.  
  1331.    This function takes one argument, and enumerated type (bfd_format)
  1332. and returns a pointer to a const string "invalid", "object",
  1333. "archive", "core" or "unknown" depending upon the value of the
  1334. enumeration.
  1335.  
  1336.      CONST char * bfd_format_string(bfd_format);
  1337.  
  1338.  
  1339.